package kr.hkit.powerjava.chapter21.work;
class NegativeBalanceException extends Exception {
	public NegativeBalanceException() {
		super("잔액보다 입출금액이 더 큽니다.");
	}
}

class BankAccount{
	private int balance;
	
	public BankAccount() { }
	
	public BankAccount(int balance) {

		this.balance = balance;
	}
	
	public void deposit(int amount){
		balance = balance + amount;
	}
	
	public int withdraw(int amount) throws NegativeBalanceException{
		if(balance < amount ){
			throw new NegativeBalanceException();
		}else {
			balance = balance - amount;
			return amount;
		}	
	}

	@Override
	public String toString() {
		return "BankAccount [Balance = "+this.balance+"]";
	}
}

public class BankAccountTest {
	public static void main(String[] args) {
		BankAccount bank = new BankAccount(150);
		try{
		bank.withdraw(200);
		} catch(NegativeBalanceException e) {
			e.printStackTrace();
		}
	}
}
